﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NJL.IDAL;
using Royalsoft.DBUtility;//Please add references
namespace NJL.SQLServerDAL
{
    /// <summary>
    /// 数据访问类:NJL_BOOK_INFOMATION
    /// </summary>
    public partial class NJL_BOOK_INFOMATION : INJL_BOOK_INFOMATION
    {
        public NJL_BOOK_INFOMATION()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from NJL_BOOK_INFOMATION");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
            parameters[0].Value = ID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(NJL.Model.NJL_BOOK_INFOMATION model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into NJL_BOOK_INFOMATION(");
            strSql.Append("ID,NJL_ATTRACTION_ID,NJL_SYS_BASE_ID,TICKET_TYPE,MARKET_PRICE,LOCAL_PRICE,BACK_PRICE,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME)");
            strSql.Append(" values (");
            strSql.Append("@ID,@NJL_ATTRACTION_ID,@NJL_SYS_BASE_ID,@TICKET_TYPE,@MARKET_PRICE,@LOCAL_PRICE,@BACK_PRICE,@UPDATE_USER_NAME,@UPDATE_USER_ID,@UPDATE_DATE_TIME,@CREATE_USER_NAME,@CREATE_USER_ID,@CREATE_DATE_TIME)");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20),
					new SqlParameter("@NJL_ATTRACTION_ID", SqlDbType.VarChar,20),
					new SqlParameter("@NJL_SYS_BASE_ID", SqlDbType.VarChar,20),
					new SqlParameter("@TICKET_TYPE", SqlDbType.VarChar,20),
					new SqlParameter("@MARKET_PRICE", SqlDbType.Money,8),
					new SqlParameter("@LOCAL_PRICE", SqlDbType.Money,8),
					new SqlParameter("@BACK_PRICE", SqlDbType.Money,8),
					new SqlParameter("@UPDATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@UPDATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@UPDATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime)};
            parameters[0].Value = model.ID;
            parameters[1].Value = model.NJL_ATTRACTION_ID;
            parameters[2].Value = model.NJL_SYS_BASE_ID;
            parameters[3].Value = model.TICKET_TYPE;
            parameters[4].Value = model.MARKET_PRICE;
            parameters[5].Value = model.LOCAL_PRICE;
            parameters[6].Value = model.BACK_PRICE;
            parameters[7].Value = model.UPDATE_USER_NAME;
            parameters[8].Value = model.UPDATE_USER_ID;
            parameters[9].Value = model.UPDATE_DATE_TIME;
            parameters[10].Value = model.CREATE_USER_NAME;
            parameters[11].Value = model.CREATE_USER_ID;
            parameters[12].Value = model.CREATE_DATE_TIME;

            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters)>0?true:false;
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(NJL.Model.NJL_BOOK_INFOMATION model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update NJL_BOOK_INFOMATION set ");
            strSql.Append("NJL_ATTRACTION_ID=@NJL_ATTRACTION_ID,");
            strSql.Append("NJL_SYS_BASE_ID=@NJL_SYS_BASE_ID,");
            strSql.Append("TICKET_TYPE=@TICKET_TYPE,");
            strSql.Append("MARKET_PRICE=@MARKET_PRICE,");
            strSql.Append("LOCAL_PRICE=@LOCAL_PRICE,");
            strSql.Append("BACK_PRICE=@BACK_PRICE,");
            strSql.Append("UPDATE_USER_NAME=@UPDATE_USER_NAME,");
            strSql.Append("UPDATE_USER_ID=@UPDATE_USER_ID,");
            strSql.Append("UPDATE_DATE_TIME=@UPDATE_DATE_TIME,");
            strSql.Append("CREATE_USER_NAME=@CREATE_USER_NAME,");
            strSql.Append("CREATE_USER_ID=@CREATE_USER_ID,");
            strSql.Append("CREATE_DATE_TIME=@CREATE_DATE_TIME");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@NJL_ATTRACTION_ID", SqlDbType.VarChar,20),
					new SqlParameter("@NJL_SYS_BASE_ID", SqlDbType.VarChar,20),
					new SqlParameter("@TICKET_TYPE", SqlDbType.VarChar,20),
					new SqlParameter("@MARKET_PRICE", SqlDbType.Money,8),
					new SqlParameter("@LOCAL_PRICE", SqlDbType.Money,8),
					new SqlParameter("@BACK_PRICE", SqlDbType.Money,8),
					new SqlParameter("@UPDATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@UPDATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@UPDATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
            parameters[0].Value = model.NJL_ATTRACTION_ID;
            parameters[1].Value = model.NJL_SYS_BASE_ID;
            parameters[2].Value = model.TICKET_TYPE;
            parameters[3].Value = model.MARKET_PRICE;
            parameters[4].Value = model.LOCAL_PRICE;
            parameters[5].Value = model.BACK_PRICE;
            parameters[6].Value = model.UPDATE_USER_NAME;
            parameters[7].Value = model.UPDATE_USER_ID;
            parameters[8].Value = model.UPDATE_DATE_TIME;
            parameters[9].Value = model.CREATE_USER_NAME;
            parameters[10].Value = model.CREATE_USER_ID;
            parameters[11].Value = model.CREATE_DATE_TIME;
            parameters[12].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from NJL_BOOK_INFOMATION ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
            parameters[0].Value = ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from NJL_BOOK_INFOMATION ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public NJL.Model.NJL_BOOK_INFOMATION GetModel(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 ID,NJL_ATTRACTION_ID,NJL_SYS_BASE_ID,TICKET_TYPE,MARKET_PRICE,LOCAL_PRICE,BACK_PRICE,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME from NJL_BOOK_INFOMATION ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
            parameters[0].Value = ID;

            NJL.Model.NJL_BOOK_INFOMATION model = new NJL.Model.NJL_BOOK_INFOMATION();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ID"] != null)
                {
                    model.ID = ds.Tables[0].Rows[0]["ID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NJL_ATTRACTION_ID"] != null)
                {
                    model.NJL_ATTRACTION_ID = ds.Tables[0].Rows[0]["NJL_ATTRACTION_ID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"] != null)
                {
                    model.NJL_SYS_BASE_ID = ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["TICKET_TYPE"] != null)
                {
                    model.TICKET_TYPE = ds.Tables[0].Rows[0]["TICKET_TYPE"].ToString();
                }
                if (ds.Tables[0].Rows[0]["MARKET_PRICE"].ToString() != "")
                {
                    model.MARKET_PRICE = decimal.Parse(ds.Tables[0].Rows[0]["MARKET_PRICE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LOCAL_PRICE"].ToString() != "")
                {
                    model.LOCAL_PRICE = decimal.Parse(ds.Tables[0].Rows[0]["LOCAL_PRICE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BACK_PRICE"].ToString() != "")
                {
                    model.BACK_PRICE = decimal.Parse(ds.Tables[0].Rows[0]["BACK_PRICE"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UPDATE_USER_NAME"] != null)
                {
                    model.UPDATE_USER_NAME = ds.Tables[0].Rows[0]["UPDATE_USER_NAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UPDATE_USER_ID"] != null)
                {
                    model.UPDATE_USER_ID = ds.Tables[0].Rows[0]["UPDATE_USER_ID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"].ToString() != "")
                {
                    model.UPDATE_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CREATE_USER_NAME"] != null)
                {
                    model.CREATE_USER_NAME = ds.Tables[0].Rows[0]["CREATE_USER_NAME"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_USER_ID"] != null)
                {
                    model.CREATE_USER_ID = ds.Tables[0].Rows[0]["CREATE_USER_ID"].ToString();
                }
                if (ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString() != "")
                {
                    model.CREATE_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,NJL_ATTRACTION_ID,NJL_SYS_BASE_ID,TICKET_TYPE,MARKET_PRICE,LOCAL_PRICE,BACK_PRICE,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME ");
            strSql.Append(" FROM NJL_BOOK_INFOMATION ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" ID,NJL_ATTRACTION_ID,NJL_SYS_BASE_ID,TICKET_TYPE,MARKET_PRICE,LOCAL_PRICE,BACK_PRICE,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME ");
            strSql.Append(" FROM NJL_BOOK_INFOMATION ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 根据景点编号删除订票信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteByAttractionId(string id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from NJL_BOOK_INFOMATION");
            strSql.Append(" where NJL_ATTRACTION_ID=@NJL_ATTRACTION_ID");
            SqlParameter[] parameters = { new SqlParameter("@NJL_ATTRACTION_ID", SqlDbType.VarChar, 20) };
            parameters[0].Value = id;
            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters)>0?true:false;
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "NJL_BOOK_INFOMATION";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

